package com.ssy.lingxi.common.constant.product;

import com.ssy.lingxi.common.constant.member.RoleTypeNameEnum;
import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商品来源- 用于S2B选择上游供应/下游销售商品
 * @author lxc
 * @version 2.0.0
 * @date 2022/3/7
 */
public enum CommodityS2BSourceEnum {

    UPPER_SUPPLY(1, "上游供应商品"),
    SUB_SALE(2, "下游销售商品");

    private Integer code;
    private String name;

    CommodityS2BSourceEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public String getCHName() {
        return name;
    }

    public static String getNameByCode(Integer code) {
        CommodityS2BSourceEnum typeEnum = Arrays.stream(CommodityS2BSourceEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return typeEnum == null ? "" : LanguageHolder.getName(RoleTypeNameEnum.class, typeEnum.code);
    }

    public static Boolean contains(Integer code) {
        return Arrays.stream(CommodityS2BSourceEnum.values()).anyMatch(e -> e.getCode().equals(code));
    }
}
